package com.pengpeng.android.dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.pengpeng.android.entity.ConfigEntity;
import com.pengpeng.android.entity.MapEntity;

public class ConfigDao extends SuperDao{
	
	
	private void createTable()
	{
		String sqlstr="create table config(";
		sqlstr+="sendinterval int null";
	    sqlstr+=");";
		sqlitedb.execSQL(sqlstr);
	}//createTable
	
    private void insert(ConfigEntity configentity)
    {int sendinterval;
    	String sqlstr="insert into config(";
    	sqlstr+="sendinterval) ";
    	sqlstr+="values("+configentity.getSendinterval();
    	sqlstr+=")";
		sqlitedb.execSQL(sqlstr);
    }//insert
    
    private void delete()
    {
    	//map的记录不能删除
    }//delete
    
    public void update(ConfigEntity configentity)
    {
    	String sqlstr="update config set ";
    	sqlstr+="sendinterval="+configentity.getSendinterval();
 
		sqlitedb.execSQL(sqlstr);

    	
    }//update
    
    public ConfigEntity query()
    {
    	String sqlstr="";
		Cursor cursor=null;
		int result=0;
		ConfigEntity configentity=null;
		sqlstr="select sendinterval ";
		sqlstr+="from config";
		cursor=sqlitedb.rawQuery(sqlstr, null);
		cursor.moveToFirst();
		if(!cursor.isAfterLast())
		{
			int sendinterval=cursor.getInt(0);
			configentity.setSendinterval(sendinterval);
			
		}
		cursor.close();
        return configentity;
    }//query
    
    public void close()
    {
    	closeDatabase();
    }//close
    
    public ConfigDao()
    {
    	openDatabase();
    	if(!existTable("config"))
    	{
    		createTable();
    		ConfigEntity configentity=new ConfigEntity();
    		configentity.setSendinterval(5000);
    		insert(configentity);
    	}
    }//MapDao
  
}
